/**
 * Created by dale on 2017/10/10.
 */
/**
 * Created by dale on 2017/10/9.
 */
var useMRList;
$(document).ready(function () {
    useMRList = $('#useMRList');
    $('.xh-datagrid-toolbar').parseToolbar();

    useMRList.initDataGrid(baseUrl+'lm/mroom/getUseMR').setSelectThenEnable(['bt_list_del'],['bt_list_undo']);



    $('#bt_list_add').click(function () {
        window.top.xhTop.showModal({
            title:'申请会议室',
            content: '<iframe src="'+baseUrl+'lm/mroom/useMRForm"  style="width: 100%;;border-style: none;padding: 0px;height:260px"  scrolling="yes"   ></iframe>',
            button:'提交',
            backClose: false,
        });
    });
    

    $('#bt_list_del').click(function () {
        if(xhExtra.buttonDisabled($(this))){
            return false;
        }
        var ids=useMRList.getDataGridSelectedFields('iUMRId');
        myWindow.initPopUp({title: '确定要删除么?', text: '这些车辆申请记录将被删除!'},function () {
            $.ajax({
                url:baseUrl+'lm/mroom/delUseMR',
                data:{ids:ids},
                type:'POST',
                success:function (data) {
                    window.top.swal(
                        data,
                        '',
                        'success'
                    );
                    useMRList.dataGridReload();
                },
                error:function (data) {
                    window.top.swal(
                        data['responseText'],
                        '',
                        'error'
                    );
                }
            });
        });
    });

    $('#bt_list_undo').click(function () {
        if(xhExtra.buttonDisabled($(this))){
            return false;
        }
        var id=useMRList.getDataGridSelectedField('iUMRId');
        myWindow.initPopUp({title: '确定要撤销么?', text: '这些车辆申请记录将被撤销!'},function () {
            $.ajax({
                url:baseUrl+'lm/mroom/undoUseMR',
                data:{id:id},
                type:'POST',
                success:function (data) {
                    window.top.swal(
                        data,
                        '',
                        'success'
                    );
                    useMRList.dataGridReload();
                },
                error:function (data) {
                    window.top.swal(
                        data['responseText'],
                        '',
                        'error'
                    );
                }
            });
        });
    });

    $('#bt_list_search').click(function () {
        useMRList.addDataGridParams(getParams());
    });

    DataGrid.onDblClickRow=function (rowIndex, rowData) {
        var iUMRId = rowData['iUMRId'];
        window.top.xhTop.showModal({
            title:'审批申请',
            content:'<iframe src="'+baseUrl+'lm/mroom/useMRForm?iUMRId='+iUMRId+'" style="height: 260px;border-style: none;padding: 0px;width: 100%;"></iframe>',
            button:'提交',
            backClose: false
        });
        return false;
    }
});

function getParams() {
    var key=xhExtra.getValue($('#list_search'));
    var state=xhExtra.getValue($('#select_state'));
    var params={key:key,state:state};
    return params;
}